<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>站细列表页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/frontEnd/images/favicon.ico">
    <link rel="stylesheet" href="/layuicms/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/layuicms/css/public.css" media="all" />
    <script charset="utf-8" src="/layuicms/js/x-layui.js"></script>
</head>
<body class="childrenBody">
<!-- 查询条件开始 -->
<!--    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
        <legend>查询条件</legend>
    </fieldset>-->
<blockquote class="layui-elem-quote" style="height: 50px;">
    <form action="" method="post" id="searchFrm" lay-filter="searchFrm" class="layui-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 100px;">条目搜索</label>
                <div class="layui-input-inline" style="width: 300px">
                    <input type="text" name="typename"  autocomplete="off" class="layui-input" placeholder="请输入条目名称，例如'第1条'">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-block" style="text-align: center;">
                    <button type="button" class="layui-btn" lay-submit="" lay-filter="doSearch"> <span class="layui-icon layui-icon-search"></span> 查询</button>
                    <button type="reset" class="layui-btn layui-btn-warm"><span class="layui-icon layui-icon-refresh-1"></span> 重置</button>
                </div>
            </div>
        </div>
    </form>
</blockquote>
<!--查询条件结束-->
<!--数据表格开始-->
<div>

    <table class="layui-hide" id="standFineListTable" lay-filter="standFineListTable"></table>

    <div id="standFineListToolBar" style="display: none ;"  >
        <button type="button" lay-event="add" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-add-circle"></span> 添加站细</button>
        <button type="button" lay-event="sync" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-add-circle"></span> 站细内容一键同步</button>
    </div>
    <div id="standFineListRowBar" style="display: none">
        <input type="hidden" id="editId" name="standFileId">
        <input type="hidden" id="stationId" name="sid">
        <button type="button" lay-event="lookOver" class="layui-btn layui-btn-sm  layui-btn-warm"><span class="layui-icon layui-icon-refresh-3"></span> 查看</button>
        <button type="button" lay-event="editStandFile" class="layui-btn layui-btn-sm layui-btn-normal"><span class="layui-icon layui-icon-util"></span> 编辑</button>
        <button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger"><span class="layui-icon layui-icon-delete"></span> 删除</button>
        <button type="button" lay-event="update" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-download-circle"></span> 文件下载</button>
    </div>
</div>
<!--数据表格结束-->

<!--添加和修改弹出层开始-->
<div style="display: none;padding: 10px;" id="addOrUpdateDiv">

    <form action="" method="post" class="layui-form" id="dataFrm" lay-filter="dataFrm">
        <div class="layui-form-item">
            <label class="layui-form-label">车站名称</label>
            <div class="layui-input-block">
                <input type="hidden" name="id">
                <select name="sid" class="stationName" id="sid" lay-filter="standId">
                    <option value="0">请选择车站</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">站细名称</label>
            <div class="layui-input-block">
                <input placeholder="文档名称会根据车站名称自动生成" id="documentName" class="layui-input" name="documentName">
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="doSubmit" id="doSubmit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

</div>
<!--添加和修改弹出层结束-->

</body>
<script type="text/javascript" src="/layuicms/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['jquery','form','table','layer',],function(){
        var $ = layui.jquery;
        var form=layui.form;
        var table = layui.table;
        var layer = layui.layer;
        //初始化时间选择器
        //加载数据
        var tableIns = table.render({
            elem: '#standFineListTable'
            ,url:'/standFineList/loadAllStandFineList'
            ,toolbar: '#standFineListToolBar' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: '安全类型数据表'
            ,height:'full-140'
            ,page: true
            ,cols: [ [
                {field:'',title:'序号', type:'numbers', width:80, align: 'center', unresize: true, sort: true}
                ,{field:'documentName', width:220,title:'文档名称',align: 'center'}
                ,{field:'createDate', width:220,title:'修定时间' , align: 'center'}
                ,{field:'modifyPersonName',width:200, title:'修订人' , align: 'center'}
                ,{fixed: 'right', title:'操作', toolbar: '#standFineListRowBar' ,align: 'center'}
            ] ]
        });

        //加载查询条件供应商的下拉列表
        $.get("/station/loadAllStationForSelect",function(res){
            var data=res.data;
            var dom=$(".stationName");
            var html='<option value="">请选择车站</option>'
            $.each(data,function(index,item){
                html+='<option value="'+item.id+'">'+item.title+'</option>'
            });
            dom.html(html);
            form.render("select");
        });

        //模糊查询
        form.on("submit(doSearch)",function (data) {
            tableIns.reload({
                where:data.field,
                page:{
                    curr:1
                }
            });
            return false;
        });
        //监听工具条事件
        table.on('toolbar(standFineListTable)', function(obj){
            switch(obj.event){
                case 'batchDelete':
                    batchDelete();
                    break;
                case 'add':
                    openAddLayer();
                    break;
                case 'sync':
                    syncStandFile();
                    break;
            };
        });
        //监听行工具条事件
        table.on('tool(standFineListTable)', function(obj){
            var data = obj.data; //获得当前行数据
            switch(obj.event){
                case 'update':
                    openUpdateLayer(data);
                    break;
                case 'delete':
                    deleteStandFineList(data);
                    break;
                case 'editStandFile':
                    admin_edit('编辑 '+data.documentName, '/stand/toEditStandFile', data,'1000', '800')
                    break;
                case 'lookOver':
                    lookOver(data);
                    break;
            };
        });
        var mainIndex;
        var url;

        //打开添加的弹出层
        function openAddLayer() {
            mainIndex = layer.open({
                type:1,
                content:$("#addOrUpdateDiv"),
                area:['500px','280px'],
                title:'添加站细',
                success:function () {
                    $("#dataFrm")[0].reset();
                    url="/standFineList/addStandFineList"
                }
            });
        }
        /*同步*/
        function syncStandFile() {
            $.ajax({
                url: "/standFineList/syncStandFile",
                type: 'post',
                beforeSend: function () {
                    loading("数据提交中，请稍后......");
                },
                success: function (res) {
                    if(res.code==20000){
                        layer.msg(res.message, {icon: 6});
                        layer.close(index);
                    }
                    layer.msg(res.message, {icon: 6});

                }
            })
        }
        function loading(msg) {
            layer.msg(msg, {
                icon: 16,
                shade: [0.1, '#fff'],
                time: false  //不自动关闭
            })
        }
        //打开修改弹出层
        function openUpdateLayer(data) {
            $('#typename').attr("disabled",true)
            mainIndex = layer.open({
                type:1,
                content:$("#addOrUpdateDiv"),
                area:['500px','300px'],
                title:'修改站细',
                success:function () {
                    $("#dataFrm")[0].reset();
                    form.val("dataFrm",data);
                    url="/standFineList/updateStandFineList"
                }
            });
        }
        /*查看站细*/
        function lookOver(data){
            var dataId = data.id
            $("#editId").val(dataId);
            var index = layui.layer.open({
                title : data.documentName+"详情",
                type : 2,
                fix: false, //不固定
                maxmin: true,
                content : "/stand/toLookOverStandFile",
                success : function(layero, index){
                    var body = layui.layer.getChildFrame('body', index);
                    setTimeout(function(){
                        layui.layer.tips('点击此处返回用户列表', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    },500)
                }
            })
            layui.layer.full(index);
            window.sessionStorage.setItem("index",index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize",function(){
                layui.layer.full(window.sessionStorage.getItem("index"));
            })
        }
        //编辑站细
        var mainIndex;
        var url;
        function admin_edit(title, url,data, w, h) {
            var dataId = data.id;
            var sid = data.sid;
            $("#stationId").val(sid);
            $("#editId").val(dataId);
            x_my_show(title, url, w, h);
            setTimeout(function(){
                layui.layer.tips('点击此处返回站细列表', '.layui-layer-setwin .layui-layer-close', {
                    tips: 3
                });
            },600)
        }
        //监听选择车站后失去焦点事件
        form.on('select(standId)', function(data){
            $.get("/standFineList/changeStandFileName",{sid:data.value},function (res) {
                $("#documentName").val(res.documentName);
            })
        });
        //添加和修改的提交
        form.on("submit(doSubmit)",function (data) {
            $.post(url,data.field,function (res) {
                if(res.code==20000){
                    tableIns.reload();
                }
                layer.msg(res.message, {icon: 6});
                layer.close(mainIndex);
            })
            return false
        });

        //根据ID删除
        function deleteStandFineList(data) {
            layer.confirm('你确定删除【'+data.documentName+'】吗?', {icon: 3, title:'提示'}, function(index){
            $.post("/standFineList/deleteStandFineList",{id:data.id},function (res) {
                        if(res.code==20000){
                            tableIns.reload();
                        }
                        layer.close(res.message);
                    })
                    layer.close(index);
                }
            )};
    });
</script>
</html>